﻿using JESAI.EventBus.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JESAI.EventBus.Attributes
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
    public class EventSubscribeAttribute : Attribute
    {
        public EventSubscribeAttribute(object eventId)
        {
            if (eventId is string)
            {
                EventId = eventId as string;
            }
            else if (eventId is Enum)
            {
                EventId = Helper.ParseToString((eventId as Enum));
            }
            else
            {
                EventId = Helper.ParseToString(eventId);
            }
        }

        /// <summary>
        /// 事件 Id
        /// </summary>
        public string EventId { get; set; }

        /// <summary>
        /// 重试次数
        /// </summary>
        public int RetryCount { get; set; } = 0;

        public int RetryInterval { get; set; } = 1000;

        public Type[] ExceptionTypes { get; set; }
        /// <summary>
        /// 排序
        /// </summary>
        /// <remarks>数值越大的先执行</remarks>
        public int Order { get; set; } = 0;
        public bool IsEnabledGCCollect { get; set; } = false;

        public bool IsEnabledPattern { get; set; } = false;

        public TimeSpan[] RetryIntervals { get; set; }
    }
}
